<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Document</title>
		<script>
			//文档加载完成会直接执行该方法
			window.onload = function(){
				console.log("文档加载完成");

			};
			window.onerror = function(){
				console.log("文档加载失败");
			};
			//图片加载完成会执行 img.onload
			//图片加载失败会执行 img.onerror
			// cols.log("666");
		</script>
	</head>
	<body>
	  <textarea name="" id="" cols="30" rows="10"></textarea>
	  <form action="">
	  	姓名： <input type="text"id="user">
	  	密码： <input type="password"id="pwd">
	  	<input type="submit"value="提交">
	  </form>

	</body>	
</html>
<script>
	var textarea = document.querySelector("textarea");
	textarea.onselect = function(){
		console.log("选中");
	};
	textarea.oncut = function(){
		console.log("剪切");
	};
	textarea.onpaste = function(){
		console.log("粘贴");
			};


	var form = document.querySelector("form");
	//form表单提交事件
	form.onsubmit = function(e){
		//获取元素
		var userInput = document.getElementById("user");
		var pwdInput = document.getElementById("pwd");
		if(!userInput.value){
			return false;
			//自动聚焦
			userInput.focus();
			//失去焦点
			// userInput.blur();
			// e.preventDefault();
			// return;
		}

		if(!pwdInput.value){
			pwdInput.focus();
			return false;
		}
	};
	userInput = document.getElementById("user");
	//聚焦事件
	userInput.onfocus = function(){
		console.log("聚焦");

	};
	//失焦事件
	userInput.onblur = function(){
		console.log("失焦");
};
     var pwdInput = document.getElementById("pwd");
     pwdInput.onchange = function(){
     	console.log("内容变了");
     };
 




		</script>
